package com.master_jpeg.visual;

import com.master_jpeg.img.JImageContainer;
import com.master_jpeg.img.JImagePanel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeListener;
import java.io.File;

/**
 * Класс основного окна просмотра
 *
 */
public class JImageFrame extends JFrame {

    private JImagePanel panel;
    private JImageContainer container;
    private JCheckBox metods;
    private JFrame chooseDecodeMethod;
    protected JImageFrame frame;
    ImageIcon ii;


    public JImageFrame(){

        setTitle("ImageViewer");
        setSize(new Dimension(1200, 800));
        this.setLayout(new GridLayout(1,2));
        panel = new JImagePanel();
        panel.setToolTipText("Исходное изображение");
        panel.setSize(new Dimension(600, 800));
        container = new JImageContainer();
        container.setToolTipText("Преобразуемый фрагмент");
        container.setSize(new Dimension(600, 800));
        panel.setContainer(container);
        this.add(panel);
        this.add(container);
        frame = this;




        final JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File("."));

        JMenuBar menuBar = new JMenuBar();
        setJMenuBar(menuBar);

        JMenu menu = new JMenu("File");
        menuBar.add(menu);


        JMenuItem openItem = new JMenuItem("Open");
        menu.add(openItem);
        openItem.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent event)
            {
                chooser.setCurrentDirectory(new File("."));
                int result = chooser.showOpenDialog(JImageFrame.this);

                if (result == JFileChooser.APPROVE_OPTION) {
                    panel.setImage(chooser.getSelectedFile().getPath());

                }
            }
        });


        JMenuItem exitItem = new JMenuItem("Exit");
        menu.add(exitItem);
        exitItem.addActionListener(new ActionListener()
        {
            @Override
            public void actionPerformed(ActionEvent event)
            {
                System.exit(0);
            }
        });

        JMenu options = new JMenu("Options");
        menuBar.add(options);

        JMenuItem decodeMethods = new JMenuItem("Decode");
        options.add(decodeMethods);

        decodeMethods.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

            }
        });


    }


}
